import { createRouter, createWebHashHistory } from 'vue-router'
// import { ElMessage } from 'element-plus'
const Home = () => import('view/home/HomeView.vue')
// const LoginView = () => import('../view/login/LoginView.vue')
const LoginView = () => import('view/login/LoginItem.vue')
const CarDeal = () => import('view/cardeal/CarDeal.vue')
const CarBuy = () => import('view/carbuy/CarBuy.vue')

//后台信息路由
const AdminView = () => import('view/admin/AdminView.vue')
const UserMessage = () => import('view/admin/childcomps/UserMessage.vue')
const MyCenter = () => import('view/admin/childcomps/MyCenter.vue')
const AdminUserView = () => import('view/admin/childcomps/AdminUserView.vue')
const ExchangeCode = () => import('view/admin/childcomps/ExchangeCode.vue')
const AdminHome = () => import('view/admin/childcomps/AdminHome.vue')
const OrderView = () => import('view/admin/childcomps/OrderView.vue')
//用户信息路由
const UserInfoView = () => import('view/userinfo/UserInfoView.vue')
const MyUserInfo = () => import('view/userinfo/childcomps/myinfo/MyUserInfo.vue')
const MyPassSet = () => import('view/userinfo/childcomps/mypass/MyPassSet.vue')
const LevelUp = () => import('view/userinfo/childcomps/levelup/LevelUp.vue')
const SuccessPay = () => import('view/userinfo/childcomps/levelup/levelupcomp/SuccessPay.vue')
const CartView = () => import('view/userinfo/childcomps/cart/CartView.vue')
const MyOrder = () => import('view/userinfo/childcomps/order/MyOrder.vue')


const router = createRouter({
  history: createWebHashHistory(), // hash 模式
  routes: [
    {
      path: '/',
      component: Home
    },
    {
      path: '/home',
      component: Home,
    },
    {
      path: '/login',
      component: LoginView,
    },
    {
      path: '/cardeal',
      component: CarDeal
    },
    {
      path: '/carbuy',
      component: CarBuy
    },
    {
      path: '/admin',
      component: AdminView,
      children: [
        { path: '/admin',component: MyCenter},
        { path: 'usermessage',component:UserMessage },
        { path: 'mycenter',component:MyCenter },
        { path: 'userform',component:AdminUserView },
        { path: 'adminhome',component:AdminHome },
        { path: 'exchange',component:ExchangeCode },
        { path: 'order',component:OrderView },
      ]
    },
    {
      path: '/myinfo',
      component: UserInfoView,
      children: [
        { path: '/myinfo',component: MyUserInfo},
        { path: 'myuserinfo',component:MyUserInfo },
        { path: 'mypass',component:MyPassSet },
        { path: 'levelup',component:LevelUp },
        { path: 'cart',component:CartView },
        { path: 'myorder',component:MyOrder },
      ]
    },
    {
      path: '/successpay',
      component: SuccessPay
    }
  ]
})
// router.beforeEach(function(to, from, next) {
//   if(to.path == '/home') {
//     next()
//   }else if(to.path !== '/login'){
//     const token = localStorage.getItem('token')
//     if(token) {
//       next()
//     } else {
//       ElMessage({
//         message: '请登录账号！',
//         type: 'warning',
//       })
//       next('/login')
//     }

//   }else {
//     next()
//   }
// })
export default router